#ifndef FND_GAME_2D_PAGE_PROPERTY_MAP_HPP
#define FND_GAME_2D_PAGE_PROPERTY_MAP_HPP
#include <boost/variant.hpp>
#include <string>
#include <map>
#include <pantheios/pantheios.hpp>

namespace FndGame2D {
  typedef boost::variant<int, std::string, bool, double> page_property_value_type ;
  class page_property_map {
  public:
    typedef std::map<std::string, page_property_value_type> impl_map ;
    typedef std::map<std::string, impl_map> real_impl_map ;
  private:
    real_impl_map m_values ;
  public:
    template<typename T>
    T get_value(const std::string& k,
		const std::string& group, T value_if_not_found = T()) {
      if(m_values.find(k) == m_values.end() || 
	 m_values[k].find(group) == m_values[k].end()) return value_if_not_found ;
      try {
	return boost::get<T>(m_values[k][group]) ;
      } catch(boost::bad_get& e) {
	pantheios::log_DEBUG("could not find: " , k, " ex: " , e, "\n") ;
	return value_if_not_found ;
      }
    }
    template<typename T>
    bool set_value(const std::string& k,
		   const std::string& group,
		   const T& value, 
		   bool changed_if_found = false) {
      if(m_values.find(k) == m_values.end() 
	 ||m_values[k].find(group) == m_values[k].end()
	 ||changed_if_found) {
	m_values[k][group] = value ;
	return true ;
      } else {
	pantheios::log_DEBUG(k , "has exist! so could not set!\n") ;
	return false ;
      }
    }

    bool remove_key(const std::string& k) {
      return m_values.erase(k) != 0 ;
    }

    bool remove_group(const std::string& k, 
		      const std::string& group) {
      if(m_values.find(k) == m_values.end()) {
	pantheios::log_DEBUG("remove ", group, " is not in ",
			     k, "\n") ;
	return false ;
      }
      return m_values[k].erase(group) != 0 ;
    }

    bool load_info_from_file(const char* file_name) ;
    void save_info_to_file(const char* file_name) ;

  } ;
}
#endif
